<template>
  <view class="mine-container" :style="{ height: `${windowHeight}px` }">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image v-if="avatar" :src="avatar" class="cu-avatar xl round" mode="widthFix"></image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">点击登录</view>
          <view v-if="name" class="user-info">
            <view class="u_title">{{ name }}</view>
          </view>
        </view>
      </view>
    </view>

    <view class="content-section">
      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="resetPwd">
          <view class="menu-item-box">
            <image :src="resetPasswordIcon" />
            <view>重置密码</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="openPrivacyContract">
          <view class="menu-item-box">
            <image :src="privacyIcon" />
            <view>隐私及用户协议</view>
          </view>
        </view>

        <view class="list-cell list-cell-arrow" @click="showUpdates">
          <view class="menu-item-box">
            <image :src="loggerIcon" />
            <view>更新日志</view>
          </view>
        </view>
        <view class="list-cell" @click="handleLogout">
          <view class="menu-item-box">
            <image :src="loginOutIcon" />
            <view>退出账号</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import config from '@/config';
  export default {
    data() {
      return {
        name: this.$store.state.user.name,
        version: getApp().globalData.config.appInfo.version
      };
    },
    computed: {
      avatar() {
        return config.baseImgUrl + '/user.png';
      },
      resetPasswordIcon() {
        return config.baseImgUrl + '/reset-password.png';
      },
      privacyIcon() {
        return config.baseImgUrl + '/privacy.png';
      },
      loggerIcon() {
        return config.baseImgUrl + '/logger.png';
      },
      loginOutIcon() {
        return config.baseImgUrl + '/login-out.png';
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50;
      }
    },
    methods: {
      openPrivacyContract() {
        wx.openPrivacyContract();
      },
      resetPwd() {
        this.$tab.navigateTo('/packageA/pages/mine/resetPwd/resetPwd');
      },
      handleToLogin() {
        this.$tab.reLaunch('/packageA/pages/login');
      },
      showUpdates() {
        this.$tab.navigateTo('/packageA/pages/mine/updates/updates');
      },
      handleLogout() {
        this.$modal.confirm('确定注销并退出系统吗？').then(() => {
          this.$store.dispatch('LogOut').then(() => {
            this.$tab.reLaunch('/packageA/pages/login');
          });
        });
      }
    }
  };
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;
    font-size: 15px;

    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #409eff;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .logout-tip {
        font-size: 14px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          height: 28px;
          line-height: 28px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;
      font-size: 15px;

      .menu-list {
        padding: 10px 0;
      }

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }

  .menu-item-box {
    image {
      width: 20px;
      height: 20px;
      margin-right: 8px;
    }
  }
</style>